package com.twu.biblioteca.view;


import com.twu.biblioteca.model.Book;
import com.twu.biblioteca.model.Movie;
import com.twu.biblioteca.model.User;
import com.twu.biblioteca.util.Command;
import com.twu.biblioteca.util.CommandOption;

import java.util.Collection;

public class UI{
    private final Writer writer;
    private final Reader reader;
    private static final String MOVIE_TABLE_FORMAT = "%-40s | %-4s | %-20s | %-2s\n";
    private static final String BOOK_TABLE_FORMAT = "%-40s | %-20s | %-4s\n";

    public UI(Writer writer, Reader reader){
        this.writer = writer;
        this.reader = reader;
    }

    public void showWelcomeMessage() {
        writer.write("Welcome to Biblioteca");
    }

    public void showBooks(Collection<Book> books){
        writer.format(BOOK_TABLE_FORMAT, "Title", "Author", "Year Published");
        writer.format(BOOK_TABLE_FORMAT, "----------------------------------------", "--------------------", "--------------");
        for(Book book : books){
            writer.format(BOOK_TABLE_FORMAT, book.getTitle(), book.getAuthor(), book.getYearPublished());
        }
    }

    public void showMovies(Collection<Movie> movies) {
        writer.format(MOVIE_TABLE_FORMAT, "Title", "Year", "Director", "Rating");
        writer.format(MOVIE_TABLE_FORMAT, "----------------------------------------", "----", "--------------------", "--------");
        for(Movie movie : movies){
            writer.format(MOVIE_TABLE_FORMAT, movie.getTitle(), movie.getYear(), movie.getDirector(), movie.getRating());
        }
    }

    public void showOptions(Collection<CommandOption> options) {
        writer.write("Please choose from the following options:");
        for(CommandOption option : options){
            writer.write(option.toString());
        }
    }


    public String commandEntered() {
        return reader.read();
    }

    public void showInvalidMenuOption() {
        writer.write("Select a valid option!");
    }

    public void showCheckOutBookMessage() {
        writer.write("Please enter the title of the book you want to check out.");
    }

    public void showCheckoutBookSuccessMessage() {
        writer.write("Thank you! Enjoy the book.");
    }

    public void showCheckoutBookFailedMessage() {
        writer.write("That book is not available.");
    }

    public void showReturnBookMessage() {
        writer.write(("Please enter the title of the book you want to return."));
    }

    public void showReturnBookSuccessMessage() {
        writer.write("Thank you for returning the book.");
    }

    public void showReturnBookFailedMessage() {
        writer.write("That is not a valid book to return.");
    }

    public void showCheckOutMovieMessage() {
        writer.write("Please enter the title of the movie you want to check out.");
    }

    public void showCheckoutMovieSuccessMessage() {
        writer.write("Thank you! Enjoy the movie.");
    }

    public void showCheckoutMovieFailedMessage() {
        writer.write("That movie is not available.");
    }

    public void showReturnMovieMessage() {
        writer.write(("Please enter the title of the movie you want to return."));
    }

    public void showReturnMovieSuccessMessage() {
        writer.write("Thank you for returning the movie.");
    }

    public void showReturnMovieFailedMessage() {
        writer.write("That is not a valid movie to return.");
    }

    public void showLoginLibraryNumberMessage() {
        writer.write("Please enter your library number (xxx-xxxx).");
    }

    public void showLoginPasswordMessage() {
        writer.write("Please enter your password");
    }

    public void showLoginFailedMessage() {
        writer.write("Login failed.");
    }

    public void showUserInformation(User user) {
        writer.write("Name: "+user.getName()+" Email: "+user.getEmail()+" Phone: "+user.getPhoneNumber());
    }
}